<layout name="page" />
<block name="content">
	<select name="system_config_list" id="system_config_list" class="hidden">
		<option value="0">无</option>
		{:fill_option($system_config_list)}
	</select>
	{:widget('page_header/simple',array('name'=>'系统参数'))}

	<div class="tab-header">
		<a href="{:url('index')}">基本设置</a>
		<a href="{:url('weixin')}">微信设置</a>
		<a href="{:url('weixin_menu')}">微信菜单</a>
		<a class="active" href="{:url('config')}">系统参数</a>
		<a href="{:url('push')}">推送设置</a>
	</div>

	<div class="operate-panel">
		<i class="mid"></i>
		<a class="btn btn-normal" onclick="add()">新增</a>
		<a class="btn btn-normal" onclick="save()">保存</a>
		<i class="split"></i>
		<a class="btn btn-del" onclick="del()">删除</a>
	</div>
	<div class="x1 sub box">
		<div class="w30 m100 frame" style="max-height: 400px;overflow-y: scroll;">
			<div class="tree-menu">
				{:widget('html/tree_menu',array($tree_menu))}
			</div>
		</div>
		<div style="width:16px;"></div>
		<div class="x1 frame" style="height:400px;">
			<form id="form_data" name="form_data" method="post" class="common">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="data_type" value="common">
				<input type="hidden" name="opmode" id="opmode" value="">
				<div class="box">
					<label class="input-label" for="code">编码*：</label>
					<input class="input w19" type="text" id="code" name="code" check="required" info="请输入编码">
				</div>
				<div class="box">
					<label class="input-label" for="name">名称*：</label>
					<input class="input w19" type="text" id="name" name="name" check="required" info="请输入名称">
				</div>
				<div class="box">
					<label class="input-label" for="val">数据*：</label>
					<input class="input w19" type="text" id="val" name="val" check="required" info="请输入数据">
				</div>

				<div class="box">
					<label class="input-label" for="pid_name">父级*：</label>
					<div class="input-box w19">
						<input name="pid" id="pid" type="hidden" info="请选择上级部门" check="required" />
						<input name="pid_name" class="input" id="pid_name"  type="text" readonly="readonly" info="请选择父级" check="required"/>
						<a class="add-on w6" onclick="select_pid()"> 选择 </a>
					</div>
				</div>
				<div class="box">
					<label class="input-label" for="sort">排序：</label>
					<input class="input w10" type="text" id="sort" name="sort" >
				</div>
				<div class="box">
					<label class="input-label" for="is_del">状态*：</label>
					<select   name="is_del" id="is_del1" class="select w10">
						<option  value="0">启用</option>
						<option value="1">禁用</option>
					</select>
					<i class="icon"></i>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use('global', function() {
			var fn = {
				add : function() {
					winopen("{:url('add')}", 560, 470);
				},
				save : function() {
					send_form("form_data", "{:url('save')}", "{:url('config')}", function(ret) {
						if (ret.status) {
							layer.msg(ret.info, {
								time : 1200
							}, function() {
								location.reload(true);
							});
						} else {
							layer.msg(ret.info);
							return false;
						}
					});
				},
				del : function() {
					if ($(".tree-menu a.active").length == 0) {
						layer.msg('请选择要删除的数据');
						return false;
					}
					if ($(".tree-menu a.active + input").length > 0) {
						layer.msg('有子节点不能删除');
						return false;
					}
					//信息框-例2
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							var vars = $("#form_data").serialize();
							send_ajax("{:url('del')}", vars, function(ret) {
								if (ret.status) {
									layer.msg(ret.info, {
										time : 1200
									}, function() {
										location.reload(true);
									});
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				},
				select_pid : function() {
					winopen("{:url('select_pid')}", 560, 470);
				}
			};
			win_exp(fn);

			$(".tree-menu a").click(function() {
				$(".tree-menu a.active").removeClass("active");
				$this = $(this);
				$this.addClass("active");
				var vars = {};
				vars.id = $this.attr("node");
				send_ajax("{:url('read')}", vars, function(data) {
					show_data(data);
				});
				return false;
			});

			function show_data(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				$("#pid_name").val($("#system_config_list option[value='" + result.data['pid'] + "']").text());
				$("#opmode").val("edit");
			};
		});
	</script>
</block>